/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package main.rendering;

import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
import main.environment.IEnvironment;
import main.environment.Location;

/**
 *
 * @author Fox
 */
public class Panel extends JPanel{
    private IEnvironment environment;
    
    public Panel(IEnvironment e) {
        environment = e;
        
        setFocusable(true);
        setDoubleBuffered(true);
    }
    
    public void paint(Graphics g) {
        super.paint(g);
        
        for (int y = 0; y < environment.getHeight(); y++) {
            for (int x = 0; x < environment.getWidth(); x++) {
                Location l = new Location(x,y);
                if (environment.floorAt(l) != null){
                    g.drawImage(environment.floorAt(new Location(x,y)), x*environment.getDimension(), y*environment.getDimension(), this);
                }
                if (environment.blockAt(l) != null){
                    g.drawImage(environment.blockAt(new Location(x,y)), x*environment.getDimension(), y*environment.getDimension(), this);
                }
            }
        }
    }
}
